Ext.define('Emp.view.PasswordEdit', {
	extend: 'Ext.window.Window',
	alias: 'widget.passwordedit',
	
	requires: [],
	
	title: '更改密码',
	resizable: false,
	modal: true,
	width: 300,
	height: 150,
	layout: 'fit',
	
	initComponent: function() {
		var me = this;
		
		me.items = [{
			xtype: 'form',
			border: false,
			bodyPadding: 5,
			layout: 'anchor',
			defaults: {
				labelAlign: 'right',
				labelWidth: 70,
				anchor: '90%'
			},
			defaultType: 'textfield',
			items: [{
					fieldLabel: '旧密码',
					name: 'password',
					allowBlank: false
				}, {
					fieldLabel: '新密码',
					name: 'password1',
					allowBlank: false
				}, {
					fieldLabel: '确认密码',
					name: 'password2',
					allowBlank: false
			}]
		}];
		me.buttons = [{
				xtype: 'splitbutton',
				text: '保&nbsp;&nbsp;存',
				iconCls: 'save',
				action: 'save',
				handler: function() {
					me.doSubmit(false, me);
				},
				disabled: true,
				menu: {
			        items: [{
		        		text: '关&nbsp;&nbsp;闭',
						iconCls: 'close',
						action: 'save_close',
						handler: function() {
							me.doSubmit(true, me);
						}
		        	}]
			    }
			}, {
				text: '关&nbsp;&nbsp;闭',
				iconCls: 'close',
				action: 'close',
				handler: function() {
					me.close();
				}
		}];
		me.callParent();
		me.down('form').getForm().on('validitychange', me.onValidityChange, me);
	},
	
	doSubmit: function(close, me) {
		var form = me.down('form').getForm();
		if (form.isValid()) {
			form.submit({
				method: 'post',
				url: PATH.concat('/user/change'),
				success: function(form, action) {
					Ext.show.msg('提示', '更改成功');
					if(close === true)
						me.close();
				},
				failure: function(form, action) {
					Emp.msg.formSubmitFailure(form, action)
				}
			});
		}
    },
    
	onValidityChange: function(from, valid) {
		this.down('button[action=save]').setDisabled(!valid);
	}
});